SamplerState fontSampler;
Texture2D fontTexture;




struct PS_INPUT
{
	float4 pos   : SV_POSITION;
	float2 tex   : TEXCOORD0; 
	float4 color : TEXCOORD1;
	int4   chnl  : TEXCOORD2;
};

float4 main(PS_INPUT In) : SV_Target
{
	float4 color = fontTexture.Sample( fontSampler, In.tex );

	// Are we rendering a colored image, or 
	// a character from only one of the channels
	// When the channel is set to (0,0,0,0) then
	// the shader will assume we render a simple
	// 32bit glyph, however if the channel is set
	// to something else like (1,0,0,0) or (0,1,0,0)
	// then only that chanel's value will be used
	if( dot(vector(1,1,1,1), In.chnl) )
	{
		// Get the pixel value
		float val = dot(color, In.chnl);

		// A value above .5 is part of the actual character glyph
		// A value below .5 is part of the glyph outline
		color.rgb = val > 0.5 ? 2*val-1 : 0;
		color.a   = val > 0.5 ? 1 : 2*val;
	}

	color *= In.color;
	return color;
}
